package com.sangengblog.controller;

import com.sangengblog.domain.ResponseResult;
import com.sangengblog.domain.dto.AddArticleDto;
import com.sangengblog.domain.vo.ArticleUpdateVo;
import com.sangengblog.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/content/article")
public class ArticleController {
    @Autowired
    private ArticleService articleService;

    @PostMapping
    public ResponseResult add(@RequestBody AddArticleDto article){
        return articleService.add(article);
    }

    @GetMapping("/list")
    public ResponseResult list(Integer pageNum,Integer pageSize,String title,String summary){
        return articleService.list(pageNum, pageSize, title, summary);
    }

    @GetMapping("/{id}")
    public ResponseResult getUpdArticle(@PathVariable Long id){
        return articleService.getUpdArticle(id);
    }

    @PutMapping
    public ResponseResult updArticle(@RequestBody ArticleUpdateVo articleUpdVo){
//        System.out.println(articleUpdVo);
        return articleService.updArticle(articleUpdVo);
    }

    @DeleteMapping("/{id}")
    public ResponseResult delArticle(@PathVariable Long id){
        return articleService.delArticle(id);
    }

}